#pragma once

#include <msxml6.h>
#include <stack>

namespace XMLSAX
{
	namespace Common
	{
		class ICallDispatcher;
		class XMLElement;
	}
}

namespace XMLSAX
{
	namespace Core
	{
		class __declspec(dllexport) ParseHandler:ISAXContentHandler
		{
		private:
			std::stack<XMLSAX::Common::XMLElement *> _document;
			XMLSAX::Common::XMLElement *_currentElement;
			XMLSAX::Common::ICallDispatcher *_dispatcher;

		public:
			ParseHandler();
			virtual ~ParseHandler();

			long __stdcall QueryInterface(const struct _GUID &, void **);
			unsigned long __stdcall AddRef(void);
			unsigned long __stdcall Release();

			virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(ISAXLocator __RPC_FAR *pLocator);
			virtual HRESULT STDMETHODCALLTYPE startDocument(void);
			virtual HRESULT STDMETHODCALLTYPE endDocument(void);
			virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(const wchar_t __RPC_FAR *pPrefix, int prefixSize, const wchar_t __RPC_FAR *pUri, int uriSize);
			virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(const wchar_t __RPC_FAR *pPrefix, int prefixSize);
			virtual HRESULT STDMETHODCALLTYPE startElement(const wchar_t __RPC_FAR *pNamespaceUri, int uriSize, const wchar_t __RPC_FAR *pLocalName, int localNameSize, const wchar_t __RPC_FAR *pRawName, int rawNameSize, ISAXAttributes __RPC_FAR *pAttributes);
			virtual HRESULT STDMETHODCALLTYPE endElement(const wchar_t __RPC_FAR *pNamespaceUri, int uriSize, const wchar_t __RPC_FAR *pLocalName, int localNameSize, const wchar_t __RPC_FAR *pRawName, int rawNameSize);
			virtual HRESULT STDMETHODCALLTYPE characters(const wchar_t __RPC_FAR *pChars, int charsSize);
			virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(const wchar_t __RPC_FAR *pChars, int charsSize);
			virtual HRESULT STDMETHODCALLTYPE processingInstruction(const wchar_t __RPC_FAR *pTarget, int targetSize, const wchar_t __RPC_FAR *pData, int dataSize);
			virtual HRESULT STDMETHODCALLTYPE skippedEntity(const wchar_t __RPC_FAR *pName, int nameSize);

			void SetCallDispatcher(XMLSAX::Common::ICallDispatcher *dispatcher);
		};
	}
}